package Pro;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;


abstract class Setup {
	private static int numZero = 0,limit = 0,overFlow = 8;
	//àÃÕÂ¡ãªé¿Ñ§¡ìªÑè¹¹Õéà¾×èÍºÑ§¤Ñº Action TextField ãÊèä´éáµèµÑÇàÅ¢
	public static void setTextFieldNoInputNumber(final JTextField...txtNoNum1){
		for(final JTextField txtNoNum : txtNoNum1){
			txtNoNum.addKeyListener(new KeyListener(){
				public void keyPressed(KeyEvent key){
					if(key.getKeyChar() == KeyEvent.VK_1){
						txtNoNum.setEditable(false);
					}
					else if(key.getKeyChar() == KeyEvent.VK_2){
						txtNoNum.setEditable(false);
					}
					else if(key.getKeyChar() == KeyEvent.VK_3){
						txtNoNum.setEditable(false);
					}
					else if(key.getKeyChar() == KeyEvent.VK_4){
						txtNoNum.setEditable(false);
					}
					else if(key.getKeyChar() == KeyEvent.VK_5){
						txtNoNum.setEditable(false);
					}
					else if(key.getKeyChar() == KeyEvent.VK_6){
						txtNoNum.setEditable(false);
					}
					else if(key.getKeyChar() == KeyEvent.VK_7){
						txtNoNum.setEditable(false);
					}
					else if(key.getKeyChar() == KeyEvent.VK_8){
						txtNoNum.setEditable(false);
					}
					else if(key.getKeyChar() == KeyEvent.VK_9){
						txtNoNum.setEditable(false);
					}
					else if(key.getKeyChar() == KeyEvent.VK_0){
						txtNoNum.setEditable(false);
					}
					else if(key.getKeyChar() == KeyEvent.VK_SPACE){
						txtNoNum.setEditable(false);
					}
					
					else
						txtNoNum.setEditable(true);
					setTextField(txtNoNum);
				}

				@Override
				public void keyReleased(KeyEvent arg0) {
					
				}

				@Override
				public void keyTyped(KeyEvent arg0) {
					
				}
			});
		}
	}
	
	//àÃÕÂ¡ãªé¿Ñ§¡ìªÑè¹¹Õéà¾×èÍºÑ§¤Ñº Action TextField ãÊèä´éáµèàºÍÃìâ·Ã
	public static void setTextFieldInputTel(final JTextField...txtTelPhone1){
		for(final JTextField txtTelPhone : txtTelPhone1){
			txtTelPhone.addKeyListener(new KeyListener(){
				
				public void keyPressed(KeyEvent key){
					txtTelPhone.setEditable(false);
					txtTelPhone.setBackground(Color.white);
					txtTelPhone.setBorder(BorderFactory.createLineBorder(Color.decode("#778899")));
					if(key.getKeyChar() == KeyEvent.VK_1){
						if(numZero > 0&&numZero != 1&&numZero <=overFlow){
							txtTelPhone.setEditable(true);
							numZero++;
							limit++;
						}
					}
					else if(key.getKeyChar() == KeyEvent.VK_2){
						if(numZero > 0){
							if(numZero >= 1&&numZero <=overFlow){
								txtTelPhone.setEditable(true);
								numZero++;
								if(limit == 1)
									overFlow = 8;
								limit++;
							}
						}
					}
					else if(key.getKeyChar() == KeyEvent.VK_3){
						if(numZero > 0&&numZero != 1&&numZero <=overFlow){
							txtTelPhone.setEditable(true);
							numZero++;
							limit++;
						}
					}
					else if(key.getKeyChar() == KeyEvent.VK_4){
						if(numZero > 0&&numZero != 1&&numZero <=overFlow){
							txtTelPhone.setEditable(true);
							numZero++;
							limit++;
						}
					}
					else if(key.getKeyChar() == KeyEvent.VK_5){
						if(numZero > 0&&numZero != 1&&numZero <=overFlow){
							txtTelPhone.setEditable(true);
							numZero++;
							limit++;
						}
					}
					else if(key.getKeyChar() == KeyEvent.VK_6){
						if(numZero > 0&&numZero != 1&&numZero <=overFlow){
							txtTelPhone.setEditable(true);
							numZero++;
							limit++;
						}
					}
					else if(key.getKeyChar() == KeyEvent.VK_7){
						if(numZero > 0&&numZero != 1&&numZero <=overFlow){
							txtTelPhone.setEditable(true);
							numZero++;
							limit++;
						}
					}
					else if(key.getKeyChar() == KeyEvent.VK_8){
						if(numZero > 0&&numZero <=overFlow){
							if(numZero >= 1){
								txtTelPhone.setEditable(true);
								numZero++;
								if(limit == 1)
									overFlow = 9;
								limit++;
								
							}
						}
					}
					else if(key.getKeyChar() == KeyEvent.VK_9){
						if(numZero > 0&&numZero != 1&&numZero <=overFlow){
							txtTelPhone.setEditable(true);
							numZero++;
							limit++;
						}
					}
					else if(key.getKeyChar() == KeyEvent.VK_0){
						if(numZero != 1&&numZero <=overFlow){
							numZero++;
							txtTelPhone.setEditable(true);
							limit++;
						}
					}
					else if(key.getKeyChar() == KeyEvent.VK_BACK_SPACE){
						txtTelPhone.setEditable(true);
						if(numZero > 0){
							--numZero;
							limit--;
						}
					}
					else
						txtTelPhone.setEditable(false);
					setTextField(txtTelPhone);
				}
            //เรียกใช้ฟังก์ชั่นนี้เพื่อบังคับ Action TextField ใส่ได้แต่ตัวเลข
	public static void setTextFieldInputNumber(final JTextField...txtNum1){
		for(final JTextField txtNum : txtNum1){
			txtNum.addKeyListener(new KeyListener(){
				public void keyPressed(KeyEvent key){
					if(key.getKeyCode() == KeyEvent.VK_1){
						txtNum.setEditable(true);
					}
					else if(key.getKeyCode() == KeyEvent.VK_2){
						txtNum.setEditable(true);
					}
					else if(key.getKeyCode() == KeyEvent.VK_3){
						txtNum.setEditable(true);
					}
					else if(key.getKeyCode() == KeyEvent.VK_4){
						txtNum.setEditable(true);
					}
					else if(key.getKeyCode() == KeyEvent.VK_5){
						txtNum.setEditable(true);
					}
					else if(key.getKeyCode() == KeyEvent.VK_6){
						txtNum.setEditable(true);
					}
					else if(key.getKeyCode() == KeyEvent.VK_7){
						txtNum.setEditable(true);
					}
					else if(key.getKeyCode() == KeyEvent.VK_8){
						txtNum.setEditable(true);
					}
					else if(key.getKeyCode() == KeyEvent.VK_9){
						txtNum.setEditable(true);
					}
					else if(key.getKeyCode() == KeyEvent.VK_0){
						txtNum.setEditable(true);
					}
					else if(key.getKeyCode() == KeyEvent.VK_SPACE){
						txtNum.setEditable(true);
					}
					else if(key.getKeyCode() == KeyEvent.VK_SLASH){
						txtNum.setEditable(true);
					}
					
					else
						txtNum.setEditable(false);
					setTextField(txtNum);
				}

				@Override
				public void keyReleased(KeyEvent arg0) {
					// TODO Auto-generated method stub
					
				}

				@Override
				public void keyTyped(KeyEvent arg0) {
					// TODO Auto-generated method stub
					
				}
			});
		}
	}
   
	
	public static void actionMouse(final JTextField...txtName1){
		for(final JTextField txtName : txtName1){
			txtName.addMouseListener(new MouseListener(){
				@Override
				public void mouseClicked(MouseEvent e) {
					// TODO Auto-generated method stub
					if(e.getSource() == txtName){
						txtName.setText("");
						txtName.setForeground(Color.BLACK);
					}
				}

				@Override
				public void mouseEntered(MouseEvent arg0) {
					// TODO Auto-generated method stub
					
				}

				@Override
				public void mouseExited(MouseEvent arg0) {
					// TODO Auto-generated method stub
					
				}

				@Override
				public void mousePressed(MouseEvent arg0) {
					// TODO Auto-generated method stub
					
				}

				@Override
				public void mouseReleased(MouseEvent arg0) {
					// TODO Auto-generated method stub
					
				}
		});
	}
	}
	
	protected static void setTextField(JTextField field){
		field.setBackground(Color.white);
		field.setBorder(BorderFactory.createLineBorder(Color.decode("#778899")));
	
	}
}
